<template>
  <ych-modal
    :fullscreen="dialogSize === 'default' || dialogSize === 'full'"
    :size="dialogSize"
    :visible="visible"
    :destroyOnClose="true"
    :footer="null"
    :bodyStyle="bodyStyle"
    :closable="false"
    @cancel="handleCancel">
    <!--<template slot="footer">
      <a-button key="close" @click="handleCancel">关闭</a-button>
    </template>-->
    <redirect :func="func" :id="id" :code="formCode" :fks="fks" @close="close"
              @refreshParent="refreshParent" :ignoreSec="ignoreSec"
              @setTitle="setTitle" :parentValue="parentValue"
              @setModelType="setModelType"
              v-on="$listeners" v-bind="$attrs" :showCloseBut="true" :processInstanceName="title"></redirect>
  </ych-modal>
</template>

<script>

  import Redirect from './Redirect'

  export default {
    name: 'RedirectModal',
    components: {
      Redirect
    },
    props: {
      ignoreSec: Boolean
    },
    data () {
      return {
        title: this.$t('m.bpm.common.bpmPage'),
        visible: false,
        func: null,
        id: null,
        formCode: null,
        fks: null,
        parentValue: {},
        dialogSize: 'default',
        modelType: null,
      }
    },
    computed: {
      bodyStyle() {
        const style = {background: '#f3f4f9'};
        if (this.modelType === 'layout') {
          style.padding = 0;
          style.margin = 0;
        }
        return style;
      },
    },
    methods: {
      handleCancel () {
        this.visible = false
      },
      //关闭页面
      close () {
        this.handleCancel()
      },
      //刷新父页面
      refreshParent () {
        this.$emit('refreshParent')
      },
      //设置标题
      setTitle (title) {
        this.title = title
      },
      // 设置模型类型，组合页面或者表单页面
      setModelType(modelType) {
        this.modelType = modelType
      },
      addFromProcess (processDefId, dialogSize) {
        this.dialogSize = dialogSize || 'default'
        this.func = 'addFromProcess'
        this.id = processDefId
        this.visible = true
      },
      addFromBusiness (formCode, fks, parentValue, dialogSize) {
        this.dialogSize = dialogSize || 'default'
        this.formCode = formCode
        this.fks = fks
        this.parentValue = parentValue || {}
        this.func = 'addFromBusiness'
        this.id = formCode
        this.visible = true
      },
      detailFromBusiness (formId, formCode, dialogSize) {
        this.dialogSize = dialogSize || 'default'
        this.formCode = formCode
        this.func = 'detailFromBusiness'
        this.id = formId
        this.visible = true
      },
      detailFromProcess (processInstanceId, dialogSize) {
        this.dialogSize = dialogSize || 'default'
        this.func = 'detailFromProcess'
        this.id = processInstanceId
        this.visible = true
      },
      detailFromManage (processInstanceId, dialogSize) {
        this.dialogSize = dialogSize || 'default'
        this.func = 'detailFromManage'
        this.id = processInstanceId
        this.visible = true
      },
      detailFromTask (taskId, dialogSize) {
        this.dialogSize = dialogSize || 'default'
        this.func = 'detailFromTask'
        this.id = taskId
        this.visible = true
      }
    }
  }
</script>
